<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="shortcut icon" href="favicon.ico">
    <div th:include="link"></div>

</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="row">
                        <div class="col-sm-10">  <h5>专题管理 &nbsp;/&nbsp;  <small>商品列表</small></h5></div>
                        <div class="col-sm-2">
                            <input type="hidden" id="sid" th:value="${id}"/>
                            <input id="pid" type="text"   name="pid" style="width: 160px;display: none;" placeholder="请输入商品ID"  required="" aria-required="true" >
                            <button type="button" class="btn btn-primary" id="category_add">添加商品</button>
                            <button type="button" class="btn btn-primary" style="display: none;" id="category_save">保存</button>
                        </div>
                    </div>

                </div>
                <div class="ibox-content">
                    <input type="text"  id="menu_code" style="display: none" />
                    <div class="alert alert-success" style="display: none" id="productTableEventsResult" role="alert">

                    </div>
                    <!-- Example Events -->
                    <div class="example-wrap">
                        <table id="productTableEvents" data-height="400" data-mobile-responsive="true" class="table table-hover">
                        </table>
                    </div>
                </div>
                <!-- End Example Events -->

            </div>
        </div>
    </div>
</div>
</div>

<div th:include="footer"></div>
<script th:src="@{/script/js/plugins/sweetalert/sweetalert.min.js}"></script>
<script type="text/javascript" th:src="@{/script/js/contabs.js}"></script>
<script>

    var sid = $("#sid").val();

    $(function () {


        $("#category_add").click(function () {
            $("#pid").show();
            $("#category_add").hide();
            $("#category_save").show();
        });
        $("#category_save").click(function () {
            var pid = $("#pid").val();
            if(pid==""||pid==null){
                toastr.error("商品ID不允许为空!");
            }else{
                $.ajax({
                    url: "/common/special/saveSpecialProduct",
                    data: sid+"_"+pid,
                    type: "post",
                    contentType: "application/json",
                    dataType:"json",
                    success: function (data) {
                        if(data["retType"] == "0") {
                            toastr.success("添加成功!");
                            $("#pid").hide();
                            $("#category_add").show();
                            $("#category_save").hide();
                            $("#productTableEvents").bootstrapTable("refresh");
                        } else {
                            alert(data["retMsg"]);
                        }
                    }
                });

            }
        });



        $('#productTableEvents').bootstrapTable({
            url: "/common/special/getSpecialProductById/"+sid,
            search: false,
            pagination: true,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pageSize:15,
            height:600,
            iconSize: 'outline',
            toolbar: '#productTableEventsToolbar',
            columns:[
                {
                    field:'id',
                    title:'ID',
                    width:40
                },
                {
                    field:'pid',
                    title:'名称',
                    width:100
                },
                {
                    field:'pname',
                    title:'名称',
                    width:350
                },
                {
                    field:'price',
                    title:'价格',
                    width:60
                },
                {
                    field:'commission',
                    title:'佣金',
                    width:60
                },

                {
                    field:'couponname',
                    title:'是否有券',
                    width:100
                },
                {
                    field:'usertype',
                    title:'平台',
                    width:60,
                    formatter: function(value, row, index) {
                        if(row.usertype == 0) {
                            return "淘宝";
                        } else {
                            return "天猫";
                        }
                    }
                },
               {
                    field:'endtime',
                    title:'结束日期',
                    width:100
                },  {
                    field:'action',
                    title:'操作',
                    width:100,
                    formatter: function(value, row, index) {
                        return [
                            '&nbsp;&nbsp;&nbsp;&nbsp;<a class="delete ml12" href="javascript:void(0)" title="删除">'+
                            '<i class="glyphicon glyphicon-remove-circle"></i></a></shiro:hasPermission>'
                        ].join('');
                    },    //紫色为添加图标（icon），插件：font-awesome，效果图见底部。
                    events: {
                        'click .delete': function(e, value, row, index) {
                            $.confirm({
                                title: '刪除!',
                                content: '确认删除吗!',
                                confirm: function(){
                                    $.ajax({
                                        url: "/common/special/delSpecialProductById",
                                        data: sid+"_"+row.pid,
                                        type: "post",
                                        contentType: "application/json",
                                        dataType:"json",
                                        success: function (data) {
                                            if(data["retType"] == "0") {
                                                toastr.success("删除成功!");
                                                $("#productTableEvents").bootstrapTable("refresh");
                                            } else {
                                                alert(data["retMsg"]);
                                            }
                                        }
                                    });
                                },
                                cancel: function(){

                                }
                            });
                        }
                    }
                },


            ]
        });


    });
</script>
</body>
</html>